
package com.jf.cloud.multishop.controller.multishop;

import com.jf.cloud.api.auth.bo.UserInfoInTokenBO;
import com.jf.cloud.api.multishop.vo.ShopDetailVO;
import com.jf.cloud.common.constant.Constant;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import com.jf.cloud.multishop.dto.ShopUserDTO;
import com.jf.cloud.multishop.service.ShopDetailService;
import com.jf.cloud.multishop.service.ShopUserService;
import com.jf.cloud.multishop.vo.ShopUserSimpleVO;
import com.jf.cloud.multishop.vo.ShopUserVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @author zz
 * @Date 2021/5/12 20:27
 */
@RequestMapping(value = "/m/apply_shop/shop_user")
@RestController("multishopShopUserController")
@Tag(name = "multishop-店铺用户信息")
public class ShopUserController {

    @Autowired
    private ShopDetailService shopDetailService;

    @Autowired
    private ShopUserService shopUserService;
    
    @GetMapping("/info")
    @Operation(summary = "登陆店铺用户信息" , description = "获取当前登陆店铺用户的用户信息")
    public ServerResponseEntity<ShopUserSimpleVO> info() {
        UserInfoInTokenBO userInfoInTokenBO = AuthUserContext.get();
        ShopUserSimpleVO shopUserSimple = new ShopUserSimpleVO();
        shopUserSimple.setIsAdmin(userInfoInTokenBO.getIsAdmin());
        shopUserSimple.setIsPassShop(userInfoInTokenBO.getIsPassShop());
        shopUserSimple.setTenantId(userInfoInTokenBO.getTenantId());
        shopUserSimple.setUserId(userInfoInTokenBO.getUserId());
        shopUserSimple.setUserName(userInfoInTokenBO.getUserName());
        if (!Objects.equals(userInfoInTokenBO.getTenantId(), Constant.DEFAULT_SHOP_ID)) {
            ShopDetailVO shopDetail = shopDetailService.getByShopId(userInfoInTokenBO.getTenantId());
            shopUserSimple.setAvatar(shopDetail.getShopLogo());
            shopUserSimple.setShopName(shopDetail.getShopName());
        }
        return ServerResponseEntity.success(shopUserSimple);
    }

    @GetMapping("/list")
    @Operation(summary = "获取店铺下的所有员工列表" , description = "获取店铺下的所有员工列表")
    public ServerResponseEntity<List<ShopUserVO>>list() {
        ShopUserDTO shopUserDTO = new ShopUserDTO();
        shopUserDTO.setShopId(AuthUserContext.get().getTenantId());
        List<ShopUserVO> shopUserVOList = shopUserService.listByShopId(shopUserDTO);
        return ServerResponseEntity.success(shopUserVOList);
    }
}
